package com.slipper.sfts.order.service.support;

import com.slipper.PaasContext;
import com.slipper.common.util.StringUtil;
import com.slipper.qmt.vo.CancelVO;
import com.slipper.sfts.api.stock.bo.StockOrderBO;
import com.slipper.sfts.order.service.IDealer;
import com.slipper.sfts.stock.service.StockOrderMessageService;
import com.slipper.sfts.stock.service.StockOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CancelDealer implements IDealer<CancelVO> {
    private static final Logger logger = LoggerFactory.getLogger(CancelDealer.class);

    @Override
    public void doDeal(CancelVO vo) {
        logger.info("接收到撤单回调消息：{}", vo);
        if (StringUtil.isBlank(vo.getStockOrderId())) return;

        StockOrderService stockOrderService = PaasContext.getBean(StockOrderService.class);
        StockOrderBO stockOrder = stockOrderService.queryBy(vo.getStockOrderId());
        if (stockOrder != null) {
            String message = "[" + stockOrder.getCode() + "]委托撤单" +
                    (vo.getResult() == 0 ? "成功" : "失败") + "。";
            PaasContext.getBean(StockOrderMessageService.class).save(
                    stockOrder.getMemberId(), stockOrder.getAccountId(), message);
        }
    }
}
